	<include file='Common:header' />

		<!-- /section:basics/navbar.layout -->
		<div class="main-container" id="main-container">

			<!-- #section:basics/sidebar -->

	<include file='Common:left' />
			<!-- /section:basics/sidebar -->
			
			<div class="main-content">
				<div class="main-content-inner">
					<div class="page-content">
						<div class="row maintop">

						<div class="col-xs-12 col-sm-3">
							<button class="btn btn-xs btn-danger" data-toggle="modal" data-target="#myModal">
								<i class="ace-icon fa fa-plus bigger-110"></i>
									添加自定义菜单
							</button>
							<!--<a class="red" href="javascript:;" onclick="we_menu_make();">-->
							<!-- <a class="red" href="{:U('we_menu_make')}"> -->
							<button class="btn btn-xs btn-info" id="we_menu_make">
								<i class="ace-icon fa fa-bolt bigger-110"></i>
									生成菜单
							</button>
							<!-- </a> -->
						</div>
					</div>

							<div class="row">
							    <div class="col-xs-12">
										<div>
											<form id="we_menu_order" name="we_menu_order" method="post" action="{:U('we_menu_order')}" >
											<table width="100%" class="table table-striped table-bordered table-hover" id="dynamic-table">
												<thead>
													<tr>
													  <th width="5%">ID</th>
													  <th width="28%">主菜单名称</th>
													  <th width="12%">菜单类型</th>
													  <th width="10%">菜单状态</th>
													  <th width="32%">菜单操作值</th>
													  <th width="7%">排序</th>
													  <th width="6%" style="border-right:#CCC solid 1px;">操作</th>
												  </tr>
												</thead>

												<tbody>

                                                <foreach name="we_menu" item="v">
													<tr>
														<td height="28">{$v.we_menu_id}</td>
														<td style='padding-left:<if condition="$v.leftpin neq 0">{$v.leftpin}px</if>' >{$v.lefthtml}{$v.we_menu_name}</td>
														<td>{$v.we_menu_type}</td>
														<td>
									<if condition='$v[we_menu_open] eq 1'>
										<a class="red" href="javascript:;" onclick="return stateyes({$v.we_menu_id});" title="已开启">
											<div id="zt{$v.we_menu_id}"><button class="btn btn-minier btn-yellow">显示状态</button></div>
										</a>
									<else/>
										<a class="red" href="javascript:;" onclick="return stateyes({$v.we_menu_id});" title="已禁用">
											<div id="zt{$v.we_menu_id}"><button class="btn btn-minier btn-danger">隐藏状态</button></div>
										</a>
									</if>
														</td>
														<td>{$v.we_menu_typeval}</td>
														<td><input name="{$v.we_menu_id}" class="list_order" value=" {$v.we_menu_order}" size="3"/></td>
														<td>
						<div class="hidden-sm hidden-xs action-buttons">
							<a class="green"  href="javascript:;" onclick="return we_menu_edit({$v.we_menu_id});"  title="修改">
								<i class="ace-icon fa fa-pencil bigger-130"></i>
							</a>
							<a class="red" href="javascript:;" onclick="return del({$v.we_menu_id});" title="删除">
								<i class="ace-icon fa fa-trash-o bigger-130"></i>
							</a>
						</div>
													</td>
													</tr>
                                                 </foreach>   
                                                  <tr>
													  <td colspan="8" align="left"><button type="submit"  id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button></td>
												  </tr>
												</tbody>
										  </table>
										  </form>
							    		</div>
						</div>
					</div>
<include file='Common:header_nav' />


<!-- 显示模态框（Modal）-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<form class="form-horizontal" name="we_menu_runadd" id="we_menu_runadd" method="post" action="__URL__/we_menu_runadd">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" 
               aria-hidden="true">×
            </button>
            <h4 class="modal-title" id="myModalLabel">
               添加自定义菜单
            </h4>
         </div>
         <div class="modal-body">
            
						<div class="row">
							<div class="col-xs-12">
								
                                	<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 上级栏目： </label>
										<div class="col-sm-10">
                                        <select name="we_menu_leftid"  class="col-sm-4 selector" >
                                        <option value="0">顶级栏目</option>
                                        <foreach name="menu_top" item="v">
                                        <option value="{$v.we_menu_id}">{$v.we_menu_name}</option>
                                        </foreach>
                                        </select>
                                        </div>
									</div>
									<div class="space-4"></div>
																		
									<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单名称：  </label>
										<div class="col-sm-10">
											<input type="text" name="we_menu_name" id="we_menu_name" placeholder="输入菜单名称" class="col-xs-10 col-sm-5" />
										</div>
									</div>
                                    <div class="space-4"></div>
								
                                	<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单类型： </label>
										<div class="col-sm-10">
                                        <select name="we_menu_type"  class="col-sm-4" >
                                        <option value="view" selected>URL菜单链接</option>
                                        <option value="click">菜单点击事件</option>
                                        </select>
                                        <span>若选择点击事件，菜单生成后请前往[自动回复设置]设置一个与下面关键字值对应的关键字回复。</span>
                                        </div>
									</div>
									<div class="space-4"></div>
																		
									<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> URL地址或关键字：  </label>
										<div class="col-sm-10">
											<input type="text" name="we_menu_typeval" id="we_menu_typeval" placeholder="输入URL地址或关键字" class="col-xs-10 col-sm-10" />
										</div>
									</div>
                                    <div class="space-4"></div>
									
									<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序：  </label>
										<div class="col-sm-10">
											<input type="text" name="we_menu_order" id="we_menu_order" value="50" class="col-xs-10 col-sm-2" />
											<span class="lbl">&nbsp;&nbsp;<span class="red">*</span>从小到大排序</span>
										</div>
									</div>
                                    <div class="space-4"></div>

									<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 是否开启： </label>
										<div class="col-sm-10" style="padding-top:5px;">
                                            <input name="we_menu_open" id="we_menu_open" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" />
											<span class="lbl">&nbsp;&nbsp;默认关闭</span>
										</div>
									</div>
                                    <div class="space-4"></div>
									
								</div>
							</div>
			
			
			
			
         </div>
         <div class="modal-footer">
		 	<button type="submit" class="btn btn-primary">
            	提交保存
            </button>
		 	<button class="btn btn-info" type="reset">
				重置
			</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">
				关闭
            </button>
         </div>
      </div><!-- /.modal-content -->
   </div><!-- /.modal-dialog -->
   </form>
</div><!-- /.modal -->








<!-- 修改自定义菜单模态框（Modal） -->
<div class="modal fade in" id="myModaledit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-backdrop fade in" id="gbbb" style="height: 100%;"></div>
<form class="form-horizontal" name="we_menu_runedit" id="we_menu_runedit" method="post" action="__URL__/we_menu_runedit">
<input type="hidden" name="we_menu_id" id="editwe_menu_id" value="" />
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" id="gb"  data-dismiss="modal" 
               aria-hidden="true">×
            </button>
            <h4 class="modal-title" id="myModalLabel">
               修改菜单
            </h4>
         </div>
         <div class="modal-body">
            
			
						<div class="row">
							<div class="col-xs-12">
								
                                	<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 上级栏目： </label>
										<div class="col-sm-10">
                                        <select name="we_menu_leftid"  id="editwe_menu_leftid"  class="col-sm-4 selector" >
                                        <option value="0">顶级栏目</option>
                                        <foreach name="menu_top" item="v">
                                        <option value="{$v.we_menu_id}">{$v.we_menu_name}</option>
                                        </foreach>
                                        </select>
                                        </div>
									</div>
									<div class="space-4"></div>
																		
									<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单名称：  </label>
										<div class="col-sm-10">
											<input type="text" name="we_menu_name" id="editwe_menu_name" placeholder="输入菜单名称" class="col-xs-10 col-sm-5" />
										</div>
									</div>
                                    <div class="space-4"></div>
								
                                	<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单类型： </label>
										<div class="col-sm-10">
                                        <select name="we_menu_type"  class="col-sm-4" id="editwe_menu_type">
                                        <option value="view" selected>URL菜单链接</option>
                                        <option value="click">关键词回复菜单</option>
                                        </select>
                                        </div>
									</div>
									<div class="space-4"></div>
																		
									<div class="form-group">
										<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> URL地址或关键字：  </label>
										<div class="col-sm-10">
											<input type="text" name="we_menu_typeval" id="editwe_menu_typeval" placeholder="输入URL地址或关键字" class="col-xs-10 col-sm-10" />
										</div>
									</div>
                                    <div class="space-4"></div>
									
								</div>
							</div>
			
			
			
			
			
         </div>
         <div class="modal-footer">
		 	<button type="submit" class="btn btn-primary">
            	提交保存
            </button>
            <button type="button" class="btn btn-default" id="gbb" >
				关闭
            </button>
         </div>
      </div><!-- /.modal-content -->
   </div><!-- /.modal-dialog -->
   </form>
</div><!-- /.modal -->



<script>
$(function(){
	$('#we_menu_runadd').ajaxForm({
		beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
		success: complete, // 这是提交后的方法
		dataType: 'json'
	});
	
	function checkForm(){
		if( '' == $.trim($('#we_menu_name').val())){
			layer.alert('菜单名称不能为空', {icon: 6}, function(index){
 			layer.close(index);
			$('#we_menu_name').focus(); 
			});
			return false;
		}
	}
	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}else{
			alert(data.info);
			return false;	
		}
	}
});


function stateyes(val){
		  $.post('{:U("we_menu_state")}',
		  {x:val},
	function(data){
	var $v=val;
		if(data.status){
			if(data.info=='状态禁止'){
				var a='<button class="btn btn-minier btn-danger">状态禁用</button>'
				$('#zt'+val).html(a);
				layer.alert(data.info, {icon: 5});
			}else{
				var b='<button class="btn btn-minier btn-yellow">状态开启</button>'
				$('#zt'+val).html(b);
				layer.alert(data.info, {icon: 6});
			}
			
		}
	});
	return false;
}

$("#we_menu_make").click(function(){
	$.ajax({
                type:"post",
                url:'{:U("we_menu_make")}',//后端地址
                dataType:'json',
                success: function(data)
                 {
                         if(data.status==1){
							layer.alert(data.info, {icon: 6});
							}else{
							layer.alert(data.info, {icon: 6});
						}
                },
                error:function(){
                     alert("请求失败");
                }
            });
});
// function we_menu_make(){

		

// 		  $.post('{:U("we_menu_make")}',

		 
// 	function(data){

// 		if(data.status==1){
// 			layer.alert(data.info, {icon: 6});
// 			}else{
// 			layer.alert(data.info, {icon: 6});
// 		}
// 	});
// 	return false;
// }




//排序提交
$(function(){
	$('#we_menu_order').ajaxForm({
		success: complete, // 这是提交后的方法
		dataType: 'json'
	});

	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}else{
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}
	}
});

//删除
function del(id){
	layer.confirm('你确定要删除吗？', {icon: 3}, function(index){
	layer.close(index);
	window.location.href="__URL__/we_menu_del/we_menu_id/"+id+"";
	});
}

//显示修改自定义菜单
function we_menu_edit(val){
		  $.post('{:U("we_menu_edit")}',
		  {we_menu_id:val},
	function(data){
		if(data.status==1){
				$(document).ready(function(){
					$("#myModaledit").show(300);
					$("#editwe_menu_id").val(data.we_menu_id);
					$("#editwe_menu_name").val(data.we_menu_name);
					$("#editwe_menu_leftid").val(data.we_menu_leftid);
					$("#editwe_menu_type").val(data.we_menu_type);
					$("#editwe_menu_typeval").val(data.we_menu_typeval);
				});
			}else{

		}
	});
	return false;
}

//修改模态框状态
$(document).ready(function(){
	$("#myModaledit").hide();
	$("#gb").click(function(){
		$("#myModaledit").hide(200);
	});
	$("#gbb").click(function(){
		$("#myModaledit").hide(200);
	});
	$("#gbbb").click(function(){
		$("#myModaledit").hide(200);
	});
});

$(function(){
	$('#we_menu_runedit').ajaxForm({
		beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
		success: complete, // 这是提交后的方法
		dataType: 'json'
	});
	
	function checkForm(){
		if( '' == $.trim($('#editwe_menu_name').val())){
			layer.alert('菜单名称不能为空', {icon: 6}, function(index){
 			layer.close(index);
			$('#editwe_menu_name').focus(); 
			});
			return false;
		}
	}
	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}else{
			alert(data.info);
			return false;	
		}
	}
});


</script>
					</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->
	<include file='Common:footer' />
    
		</div><!-- /.main-container -->
	</body>
</html>
